//
//  LoginCoordinator.swift
//  ExtremeHealth
//
//  Created by Zhongkai Li 李忠凯 on 2018/9/29.
//  Copyright © 2018 GanDongKeJi. All rights reserved.
//

import SwiftFontName

class LoginCoordinator: Coordinator {
    var childCoordinators = [Coordinator]()
    var navigationController = UINavigationController()

    var mainNavigationController: UINavigationController

    init(mainNavigationController: UINavigationController) {
        self.mainNavigationController = mainNavigationController
    }

    func start() {
        let storyboard = UIStoryboard.fromName("Login")
        let controller = storyboard.instantiateViewController(withIdentifier: "thirdPartyLogic")
        navigationController.pushViewController(controller, animated: false)
        mainNavigationController.present(navigationController, animated: true, completion: nil)
    }

    func login() {
        let storyboard = UIStoryboard.fromName("Login")
        let controller = storyboard.instantiateViewController(withIdentifier: "Login")
        navigationController.pushViewController(controller, animated: true)
    }

    func register() {
        let storyboard = UIStoryboard.fromName("Login")
        let controller = storyboard.instantiateViewController(withIdentifier: "register")
        controller.withBack()
        controller.navigationItem.titleView = generateRegisterTitleView()
        navigationController.navigationBar.applyGradient()
        navigationController.pushViewController(controller, animated: true)
    }

    private func generateRegisterTitleView() -> UIView {
        let titleLabel = UILabel()
        titleLabel.bounds = CGRect(origin: .zero, size: CGSize(width: UIScreen.main.bounds.width - 120, height: 40))
        titleLabel.text = "注册"
        titleLabel.textColor = .white
        titleLabel.font = UIFont(name: FontName.PingFangSCMedium, size: 18)
        return titleLabel
    }
}
